#include <stdio.h>

unsigned long long minfactor(unsigned long long n){
    for (unsigned long long i = 2; i*i <= n;i++){
        if (n%i == 0) return i;
    }
    return n;
}


unsigned long long operationtime(unsigned long long n){
    unsigned long long time=0;
    while (n!=0){
        n-=minfactor(n);
        time++;
    }
    return time;
}



int main(){
    int num;
    scanf("%d",&num);
    unsigned long long result[num];
    for (unsigned long long i=0;i<num;i++){
        scanf("%lld",&result[i]);
        
    }
    //printf("%d\n",1);
    for (unsigned long long i=0;i<num;i++){
        printf("%lld\n",operationtime(result[i]));
    }

    return 0;
}